package org.example.model;

import org.example.business.AddToCartBusiness;

import java.util.ArrayList;
import java.util.List;

public class ShoppingCart {
    public List<OrderItem> orderItemList;
    public int total;
    public ShoppingCart() {
        total = 0;
        orderItemList = new ArrayList<>();
    }
    public void addOrderItem(OrderItem item) {
        orderItemList.add(item);
    }
    public void removeOrderItem(OrderItem item) {
        orderItemList.remove(item);
    }
    public void calculateTotal() {
        total = 0;
        for (OrderItem item : orderItemList) {
            total += item.number;
        }
    }
    public int getTotal() {
        return total;
    }
    public void modifyOrderItem(OrderItem orderItem, int num) {
        for (OrderItem item : AddToCartBusiness.cart.orderItemList) {
            if (item.milkName.equals(orderItem.milkName) &&
                    item.imagePath.equals(orderItem.imagePath) &&
                    item.specification.equals(orderItem.specification)) {
                item.number += num;
                break;
            }
        }
    }
}
